const { regClass } = Laya;
import { GameRes } from "../../GameRes";
import { EventNames } from "../Data/EventNames";
import { PopGameOverBase } from "./PopGameOver.generated";

@regClass()
export class PopGameOver extends PopGameOverBase {
    onAwake(): void {
        this.BtnAgain.on(Laya.Event.CLICK, this, this.onClickAgain);
        this.BtnGoHome.on(Laya.Event.CLICK, this, this.onClickGoHome);
        this.BtnNext.on(Laya.Event.CLICK, this, this.onClickNext);
    }
    
    onDestroy(): void {
        this.BtnAgain.off(Laya.Event.CLICK, this, this.onClickAgain);
        this.BtnGoHome.off(Laya.Event.CLICK, this, this.onClickGoHome);
        this.BtnNext.off(Laya.Event.CLICK, this, this.onClickNext);
    }

    public showView(isWin: boolean, time: number,score:number) {
        this.BoxWin.visible = isWin;;
        this.BoxLose.visible = !isWin;
        this.TxtTime.text = time + "s";
        this.TxtScore.text = "积分：+"+score;
        this.visible = true;
    }

    public hideView() {
        this.visible = false;
    }

    private onClickAgain() { Laya.SoundManager.playSound(GameRes.clickAudio, 1); this.hideView(); Laya.stage.event(EventNames.GAME_AGAIN); }
    private onClickGoHome() { Laya.SoundManager.playSound(GameRes.clickAudio, 1);  this.hideView(); Laya.stage.event(EventNames.GAME_GO_HOME) }
    private onClickNext() { Laya.SoundManager.playSound(GameRes.clickAudio, 1);  this.hideView(); Laya.stage.event(EventNames.GAME_NEXT) }
}